package TestModel;

import java.util.LinkedList;

import DataModel.CommonLibrary.CommonDefs;
import DataModel.DesignRulesManager.CCommonUtils;
import DataModel.DesignRulesManager.CDesignRulesChecker;
import DataModel.DesignRulesManager.CDesignRulesManager;
import DataModel.DesignRulesManager.CDesignRulesViolation;
import DataModel.DesignRulesManager.CCommonUtils.EDesignRuleType;
import DataModel.LayoutManager.CLayoutManager;
import DataModel.LayoutManager.CRectangle;
import junit.framework.TestCase;

public class drCheckerTest extends TestCase {
	
	CRectangle uA1;
	CRectangle uA2;
	CRectangle uA3;
	CRectangle uA4;
	CRectangle uA5;
	CRectangle uP1;
	CRectangle uP2;
	CRectangle uP3;
	CRectangle uP4;
	CRectangle uP5;
	
	CRectangle uC1;
	CRectangle uC2;
	
	CRectangle uM1;
	CRectangle uM2;
	CRectangle uM3;
	
	
	CRectangle u2;
	CRectangle u3;
	CRectangle u4;
	CRectangle u5;
	CDesignRulesChecker cheka_ogpu;
	String filePath = "execution/designrules.txt";
	LinkedList<CRectangle> urecs;
	CDesignRulesManager drmanager;
	CLayoutManager laymanager;
	LinkedList<String> resExpectedExt;
	private LinkedList<String> resExpectedOvr;
	private LinkedList<String> resExpectedSpc;
	private LinkedList<String> resExpectedWidth;
	private LinkedList<String> resExpectedExact;
	
	public void testDR() {
		setUpTest();
		LinkedList<EDesignRuleType> rules = new LinkedList<EDesignRuleType>();
		rules.add(CCommonUtils.EDesignRuleType.EXTENSION);
		LinkedList<CDesignRulesViolation> res = cheka_ogpu.checkDR(urecs,rules);
		for (int i=0;i<resExpectedExt.size();i++) {
			assertEquals(resExpectedExt.get(i), res.get(i).toString());
			System.out.println(res.get(i).toString());
		}
		
		rules.remove(CCommonUtils.EDesignRuleType.EXTENSION);
		rules.add(CCommonUtils.EDesignRuleType.OVERLAP);
		res = cheka_ogpu.checkDR(urecs,rules);
		for (int i=0;i<resExpectedOvr.size();i++) {
			assertEquals(resExpectedOvr.get(i), res.get(i).toString());
			System.out.println(res.get(i).toString());
		}
		
		rules.remove(CCommonUtils.EDesignRuleType.OVERLAP);
		rules.add(CCommonUtils.EDesignRuleType.SPACING);
		res = cheka_ogpu.checkDR(urecs,rules);
		for (int i=0;i<resExpectedSpc.size();i++) {
			assertEquals(resExpectedSpc.get(i), res.get(i).toString());
			System.out.println(res.get(i).toString());
		}
		

		rules.remove(CCommonUtils.EDesignRuleType.SPACING);
		rules.add(CCommonUtils.EDesignRuleType.WIDTH);
		res = cheka_ogpu.checkDR(urecs,rules);
		for (int i=0;i<resExpectedWidth.size();i++) {
			assertEquals(resExpectedWidth.get(i), res.get(i).toString());
			System.out.println(res.get(i).toString());
		}
		

		rules.remove(CCommonUtils.EDesignRuleType.WIDTH);
		rules.add(CCommonUtils.EDesignRuleType.EXACT);
		res = cheka_ogpu.checkDR(urecs,rules);
		for (int i=0;i<res.size();i++) {
			assertEquals(resExpectedExact.get(i), res.get(i).toString());
			System.out.println(res.get(i).toString());
		}
		
		
		
		
		
		
		
	}
	
	private void setUpTest() {
		drmanager = new CDesignRulesManager();
		drmanager.RunFile(filePath);
		
		uA1 = new CRectangle(0,0,100,100,CommonDefs.Layer.Active,1);
		uA2 = new CRectangle(101,0,200,100,CommonDefs.Layer.Active,2);
		uA3 = new CRectangle(-10,-10,-9,-9,CommonDefs.Layer.Active,3);
		uA4 = new CRectangle(-40,-2,-36,2,CommonDefs.Layer.Active,4);
		uA5 = new CRectangle(-155,-17,-121,16,CommonDefs.Layer.Active,5);
		
		uP1 = new CRectangle(-1,-1,101,101,CommonDefs.Layer.Poly,6);
		uP2 = new CRectangle(0,0,1000,1000,CommonDefs.Layer.Poly,7);
		uP3 = new CRectangle(102,1,199,99,CommonDefs.Layer.Poly,8);
		uP4 = new CRectangle(-55,-17,-21,11,CommonDefs.Layer.Poly,9);
		uP5 = new CRectangle(-140,-2,-136,2,CommonDefs.Layer.Poly,10);
		
		uC1 = new CRectangle(2000,0,2010,10,CommonDefs.Layer.Contact,11);
		uC2 = new CRectangle(2000,20,2010,29,CommonDefs.Layer.Contact,12);
		uM1 = new CRectangle(2008,0,2018,10,CommonDefs.Layer.Metal1,13);
		uM2 = new CRectangle(2000,27,2100,40,CommonDefs.Layer.Metal1,14);
		uM3 = new CRectangle(2000,0,3000,3000,CommonDefs.Layer.Metal1,15);
		urecs =  new LinkedList<CRectangle>();
		urecs.add(uA1);
		urecs.add(uA2);
		urecs.add(uA3);
		urecs.add(uA4);
		urecs.add(uA5);
		urecs.add(uP1);
		urecs.add(uP2);
		urecs.add(uP3);
		urecs.add(uP4);
		urecs.add(uP5);
		urecs.add(uC1);
		urecs.add(uC2);
		urecs.add(uM1);
		urecs.add(uM2);
		urecs.add(uM3);
		//urecs.add(u3);
		//urecs.add(u4);
		//urecs.add(u5);
		laymanager = new CLayoutManager(urecs);
		cheka_ogpu = new CDesignRulesChecker(laymanager, drmanager);
		resExpectedExt = new LinkedList<String>();
		resExpectedOvr = new LinkedList<String>();
		resExpectedSpc = new LinkedList<String>();
		resExpectedWidth = new LinkedList<String>();
		resExpectedExact = new LinkedList<String>();
	
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [-140,-2:-136,2] Layer: Active  [-155,-17:-121,16]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [-55,-17:-21,11] Layer: Active  [-40,-2:-36,2]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [102,1:199,99] Layer: Active  [101,0:200,100]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [0,0:1000,1000] Layer: Active  [101,0:200,100]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [0,0:1000,1000] Layer: Active  [0,0:100,100]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [-1,-1:101,101] Layer: Active  [101,0:200,100]");
		resExpectedExt.add("Violation...EXTENSION Layer: Poly  [-1,-1:101,101] Layer: Active  [0,0:100,100]");
		
		resExpectedOvr.add("Violation...OVERLAP Layer: Metal1  [2000,27:2100,40] Layer: Contact  [2000,20:2010,29]");
		resExpectedOvr.add("Violation...OVERLAP Layer: Metal1  [2008,0:2018,10] Layer: Contact  [2000,0:2010,10]");
		
		resExpectedSpc.add("Violation...SPACING Layer: Contact  [2000,0:2010,10] Layer: Contact  [2000,20:2010,29]");
		resExpectedSpc.add("Violation...SPACING Layer: Active  [0,0:100,100] Layer: Active  [101,0:200,100]");

		resExpectedWidth.add("Violation...WIDTH Layer: Active  [-10,-10:-9,-9]");
		resExpectedWidth.add("Violation...WIDTH Layer: Active  [-40,-2:-36,2]");
		resExpectedWidth.add("Violation...WIDTH Layer: Poly  [-140,-2:-136,2]");
		resExpectedWidth.add("Violation...WIDTH Layer: Metal1  [2008,0:2018,10]");
		resExpectedWidth.add("Violation...WIDTH Layer: Metal1  [2000,27:2100,40]");

		resExpectedExact.add("Violation...EXACT Layer: Contact  [2000,20:2010,29]");
		
		
	}
	
}
